import {IBlockImage,ITypeImage} from '../../interface/img';
import {INIT_TYPE_IMAGE,SET_CUR_TYPELIST,SET_ACTIVE_INDEX,INIT_TYPE_LIST} from '../types/img.type';

interface IImg{
    typeImage:ITypeImage[],
    curTypeList:IBlockImage[],
    activeIndex:number
}

const initState:IImg = {
    typeImage:[],       //分类图片列表
    curTypeList:[],      //当前指定分类图片列表
    activeIndex:-1       //swiperc初始展示的图片
}

const imgReducer = (state=initState,action:any) => {
    switch (action.type) {
        case INIT_TYPE_IMAGE:
            
            return {...state,typeImage:[...action.list]};
        
        case SET_CUR_TYPELIST:

            return {...state,curTypeList:[...state.curTypeList,...action.list]};
        
        case SET_ACTIVE_INDEX:{
            return {...state,activeIndex:action.index};
        }

        case INIT_TYPE_LIST:{
            return {...state,curTypeList:[]}
        }

        default:
            return state;
    }
}

export default imgReducer